/*
* File: destroy.cpp
* 测试用例修改自泛型编程和stl 侯捷译 10.4 内存管理基本元素
*/
#include "Allocator.h"
#include <iostream>
#include <algorithm>
class Int {
public:
	Int (int x) : val(x) { std::cout << "Int(" << val << ")" << std::endl;}
	~Int() { val = 0; std::cout << "~Int()" << std::endl;}
	int get() const { return val; }
	
private:
	int val;
};

void display(const Int & x)
{
	std::cout << x.get() << std::endl;
}

int main()
{
	Int A[] = { Int(1), Int(2), Int(3)};
	Allocator<Int> a;

	a.destroy(A, A + 3);
	std::for_each(A, A+3, display);
	a.construct(A + 0, Int(10));
	a.construct(A + 1, Int(11));
	a.construct(A + 2, Int(12));

	std::for_each(A, A+3, display);
}
